package com.ra.landlord;

import java.util.List;
import javax.annotation.Resource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Service;
import com.googlecode.cswish.model.PageInfo;
import com.googlecode.cswish.struts.spring.GenericService;

/**
 * 品牌公寓服务
 * 
 * @author colin
 * 
 */
@Service
public class BlandApartmentService {

	private static final Log logger = LogFactory
			.getLog(BlandApartmentService.class);

	@Resource
	private GenericService genericService;

	@Resource
	private LandlordUserService landlordUserService;

	/**
	 * 增加一个品牌公寓
	 * 
	 * @param blandApartment
	 * @return
	 */
	public BlandApartment addBlandApartment(BlandApartment ba) {

		LandlordOwnerUser landlordOwnerUser = landlordUserService
				.getLandlordOwnerUser();
		LandlordUser landlordUser = landlordUserService.getLandlordUser();
		ba.setLandlordUser(landlordOwnerUser);
		ba.setCreateUser(landlordUser);
		ba.setScore(0L);

		return genericService.add(ba);

	}

	/**
	 * 获取积分最高的6个品牌公寓
	 * 
	 * @return
	 */
	public List<BlandApartment> getFirstPageBlandApartments() {

		BlandApartment blandApartment = new BlandApartment();

		String strOrderBy = "score";

		PageInfo<BlandApartment> blandApartmentPageInfo = this.genericService
				.search(blandApartment, 0, 5, null, strOrderBy + " desc",
						false, null, null, true, false);

		return blandApartmentPageInfo.getData();

	}

	/**
	 * 查询指定品牌公寓ID的详细信息
	 * 
	 * @param blandApartment
	 * @return
	 */
	public BlandApartment lookBlandApartmentDetail(Integer id) {

		return this.genericService.load(BlandApartment.class, id);

	}

}
